package com.health.adapter;

import java.util.List;

import com.health.R;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tools.GlobalConts;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * listAdapter
 * 
 * @author nova
 *
 */
public class AdminHomeListAdapter extends BaseAdapter {

	private List<ARCHIVE_BASEINFO> infoList;
	private Context context;

	public AdminHomeListAdapter(Context context, List<ARCHIVE_BASEINFO> infoList) {
		super();
		this.context = context;
		this.infoList = infoList;
	}

	public void setInfoList(List<ARCHIVE_BASEINFO> infoList) {
		this.infoList = infoList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.dochealthmanage_list_item2, null);
			holder = new ViewHolder();
			holder.nameTv = (TextView) convertView.findViewById(R.id.tongji_list_name);
			holder.photoImg = (ImageView) convertView.findViewById(R.id.tongji_list_img);
			holder.ageTv = (TextView) convertView.findViewById(R.id.tongji_list_age);
			holder.isQyTv = (TextView) convertView.findViewById(R.id.tongji_list_isqy);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final ARCHIVE_BASEINFO info = infoList.get(position);
		holder.nameTv.setText(info.getCUSTOMERNAME());
		int age=GlobalConts.getAge(info.getBIRTHDAY());
		if(age!=-1){
			holder.ageTv.setText(String.valueOf(age)+"岁");
		}else{
			holder.ageTv.setText("");
		}

		if (position % 2 == 0) {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.table_row_odd));
			holder.isQyTv.setText("已签约");
		} else {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
			holder.isQyTv.setText("未签约");
		}

		return convertView;
	}


	private class ViewHolder {

		TextView nameTv;// 姓名
		ImageView photoImg;// 头像
		TextView ageTv;// 年龄
		TextView isQyTv;// 是否签约
	}

}
